package com.rocketmq.controller.consumer;

import com.rocketmq.util.RocketmqSampleUtils;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 通知系统消费者
 */
@Controller
@RequestMapping("/notice")
public class NoticeSystemConsumer {

    @RequestMapping("/consume")
    @ResponseBody
    public String consumeNotice() throws MQClientException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("NoticeSystemConsumer");
        // 填入元数据连接地址
        consumer.setNamesrvAddr("100.85.217.111:8200;100.93.3.194:8200");

        consumer.subscribe("NoticeTopic", "*");
        RocketmqSampleUtils.addMessageListener(consumer);
        consumer.start();
        return "consuming notice...";
    }
}
